package com.guocheng.modules.terminals.controller;

import com.guocheng.entity.AjaxResult;
import com.guocheng.modules.terminals.model.Terminals;
import com.guocheng.modules.terminals.service.TerminalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/terminals")
public class TerminalsController {

    @Autowired
    private TerminalService terminalService;

    @GetMapping("/index")
    public String index(Model model) {
        model.addAttribute("terminals", terminalService.selectTerminals());
        return "terminals/index";
    }

    @PostMapping("/test")
    @ResponseBody
    public AjaxResult test(Terminals terminals) {
        try {
            terminalService.login(terminals);
            return AjaxResult.ok("测试成功");
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    @PutMapping("/update")
    @ResponseBody
    public AjaxResult update(Terminals terminals) {
        int i = terminalService.updateTerminals(terminals);
        return AjaxResult.ok("更改成功");
    }
}
